#include <stdio.h>


void test85_1() {
    int inputNum;
    int max;

    do
    {
        printf("Enter a number : ");
        scanf("%d", &inputNum);
        if (max < inputNum)
        {
            max = inputNum;
        }
        

    } while (inputNum > 0);
    
    printf("The largest number entered was : %d ...\n", max);
}

// gcd计算最大公约数
int gcd(int a, int b) {
    while (b != 0)
    {
        int temp = b;
        b = a % b;
        a = temp;
    }
    
    return a;
}


void test85_2() {
    // eucild算法
    int m;
    int n;
    int a;
    printf("Enter two integers : ");
    scanf("%d %d", &m, &n);

    while (n != 0) {
        a = m % n;
        m = n;
        n = a;
    }
    printf("Greatest common divisor : %d ...\n", m);
}


void test85_3() {
    int numerator, denominator;
    printf("Enter a fraction : ");
    scanf("%d/%d", &numerator, &denominator);

    if (denominator == 0) {
        printf("Error: Denominator cannot be zero.\n");
        return;
    }

    int commonDivisor = gcd(numerator, denominator);
    printf("gcd is : %d ...\n", commonDivisor);

    numerator = numerator / commonDivisor;
    denominator = denominator / commonDivisor;

    printf("In lowest terms : %d/%d ...\n", numerator, denominator);
}

void test85_4() {

    float commission, value;
    printf("Enter value of trade : ");
    scanf("%f", &value); 

    while (value > 0)
    {
   
        if(value < 2500.00f) {
            commission = 30.00f + .017f * value;
        } else if (value < 6250.00f) {
            commission = 56.00f + .0066f * value;
        } else if (value < 20000.00f) {
            commission = 76.00f + .0034f * value;
        } else if (value < 50000.00f) {
            commission = 100.00f + .0022f * value;
        } else if (value < 500000.00f) {
            commission = 155.00f + .0011f * value;
        } else {
            commission = 255.00f + .0009f * value;
        }

        if (commission < 39.00f) {
            commission = 39.00f;
        }

        printf("Commission: $%.2f \n", commission);

        printf("Enter value of trade : ");
        scanf("%f", &value); 
    }
    

    do
    {

    } while (value > 0);

}

void test85_5() {
    int num;
    int reversedNum = 0;
    printf("Enter a number : ");
    scanf("%d",&num);

    do
    {
        reversedNum = reversedNum * 10 + num % 10;
        num /= 10;
    } while (num != 0);
    
    printf("The reversal is: %d ...\n", reversedNum);
}

void test85_8() {
    int days,week;
    printf("Enter number of days in month: ");
    scanf("%d", &days);

    printf("Enter starting day of the week(1=sun, 7=Sat):");
    scanf("%d", &week);

    int currentDay = 1;
    int day = 0;

    for (day = 0; day < week - 1; day++)
    {
        printf(" \t");
    }

    while (currentDay <= days)
    {
        printf("%d\t", currentDay);

        // 换行处理
        if ((week + currentDay - 1) % 7 == 0)
        {
            printf("\n");
        }

        currentDay++;
    } 
}

void test85_11() {
    int num, sum;
    double result = 1.0;
    double factorial = 1.0;
    printf("Enter a num : ");
    scanf("%d", &num);


    for (int i = 1; i <= num; i++)
    {
        factorial *= i;
        result += 1.0/ factorial;
    }

    printf("Result is : %f ...\n", result);
    
}

int main() {


    // test85_1();
    // test85_2();
    // test85_3();
    // test85_4();
    // test85_5();
    // test85_8();
    test85_11();


    return 0;
}